package com.zxblog.service.impl;

import com.zxblog.domain.UserAdmin;
import com.zxblog.mapper.UserAdminMapper;
import com.zxblog.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminUserServiceImpl implements AdminUserService {

    @Autowired
    private UserAdminMapper userAdminMapper;

    @Override
    public UserAdmin registerUser(String userName, String password) {
        UserAdmin userAdmin = new UserAdmin();
        userAdmin.setUsername(userName);
        userAdmin.setPassword(password);
        userAdminMapper.insertSelective(userAdmin);
        return userAdmin;
    }

    @Override
    public int removeUser(Integer uid) {
        return userAdminMapper.deleteByPrimaryKey(uid);
    }

    @Override
    public UserAdmin modifyPassword(Integer uid, String password) {
        UserAdmin userAdmin = new UserAdmin();
        userAdmin.setUid(uid);
        userAdmin.setPassword(password);
        userAdminMapper.updateByPrimaryKeySelective(userAdmin);
        return userAdmin;
    }

    @Override
    public UserAdmin loginUser(String userName,String password) {
        return userAdminMapper.selectByUserInfo(userName, password);
    }
}
